<template>
	<div>
		<ContactInfo @switchConversation="switchConversation" />
	</div>
</template>

<script lang="ts" setup>
	import { ref } from '@/TUIKit/adapter-vue';
	import TUIChatEngine, {
		TUIStore,
		StoreName,
	} from '@tencentcloud/chat-uikit-engine';

	import ContactInfo from '@/TUIKit/components/TUIContact/contact-info/index.vue';
	import { TUIGlobal } from '@tencentcloud/universal-api';
	import { onLoad } from '@dcloudio/uni-app';
	// 扫码跳转到成员信息页面
	const conversationID = ref(null);
	const currentContactInfo = ref<IContactInfoType>({} as IContactInfoType);
	onLoad((options) => {
		//判断是否为群二维码
		 if (options.conversationID.startsWith("{") && options.conversationID.endsWith("}")) {
			 let parsedData = JSON.parse(options.conversationID);
			 let GroupId = parsedData.userid
		            let objvalue = {
		            	remark: "",
		            	renderKey: "friendList-30000",
		            	source: "AddSource_Type_Web",
		            	groupID: GroupId,
		            }
		            currentContactInfo.value = objvalue;
		            TUIStore.update(StoreName.CUSTOM, 'currentContactInfo', currentContactInfo.value);
		        }else{
					conversationID.value = decodeURIComponent(options.conversationID);
					let objvalue = {
						remark: "",
						renderKey: "friendList-30000",
						source: "AddSource_Type_Web",
						userID: conversationID.value,
					}
					currentContactInfo.value = objvalue;
					TUIStore.update(StoreName.CUSTOM, 'currentContactInfo', currentContactInfo.value);
				}
		
		// conversationID.value = decodeURIComponent(options.conversationID);
		// let objvalue = {
		// 	remark: "",
		// 	renderKey: "friendList-30000",
		// 	source: "AddSource_Type_Web",
		// 	userID: conversationID.value,
		// }
		// currentContactInfo.value = objvalue;
		// console.log('扫码跳转到成员信息页面',currentContactInfo.value)
		// TUIStore.update(StoreName.CUSTOM, 'currentContactInfo', currentContactInfo.value);


	});


	const emits = defineEmits(['switchConversation']);
	const switchConversation = (data : any) => {
		TUIGlobal?.navigateTo({
			url: '@/TUIKit/components/TUIChat/index',
		});
		emits('switchConversation', data);
	};
</script>